from django import forms
from rbac import models
from django.core.exceptions import ValidationError


class UserForm(forms.Form):
    username = forms.CharField(label='用户名')
    password = forms.CharField(label='密码')
    re_password = forms.CharField(label='确认密码')
    email = forms.EmailField(label='邮箱')

    # class Meta:
    #     model = models.UserInfo
    #     fields = ['name', 'email', 'password', 're_password']

    def clean(self):
        """
        检测两次密码是否一致
        :return:
        """
        password = self.cleaned_data.get('password')
        re_password = self.cleaned_data.get('re_password')
        if password != re_password:
            raise ValidationError('两次密码输入不一致')
        return self.changed_data
